package io.github.codelifeleno.jdbrelease.config;

import java.util.Objects;
import java.util.StringJoiner;

/**
 * 脚本文件的配置
 */
public class FileConfig {
    /**
     * 文件名中的分隔符
     */
    private String nameSplit = "__";
    /**
     * 默认的要执行的文件前缀字符串
     */
    private String simplePrefix = "V";
    /**
     * 对应执行文件的回滚文件的前缀字符串
     */
    private String rollbackPrefix = "R";
    /**
     * 在每次执行过程中都要执行的文件前缀字符串
     */
    private String allwaysPrefix = "A";
    /**
     * 文件名的模板，程序会解析这个文件名的格式认作模板，并根据这个模板找寻对应的文件
     */
    private String nameRegEx = "ID${NameSplit}FILENAME${NameSplit}${Type}.sql";

    @Override
    public String toString() {
        return new StringJoiner(", ", FileConfig.class.getSimpleName() + "[", "]")
                .add("nameSplit='" + nameSplit + "'")
                .add("simplePrefix='" + simplePrefix + "'")
                .add("rollbackPrefix='" + rollbackPrefix + "'")
                .add("allwaysPrefix='" + allwaysPrefix + "'")
                .add("nameRegEx='" + nameRegEx + "'")
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;

        FileConfig fileConfig = (FileConfig) o;
        return Objects.equals(getNameSplit(), fileConfig.getNameSplit()) && Objects.equals(getSimplePrefix(), fileConfig.getSimplePrefix()) && Objects.equals(getRollbackPrefix(), fileConfig.getRollbackPrefix()) && Objects.equals(getAllwaysPrefix(), fileConfig.getAllwaysPrefix()) && Objects.equals(getNameRegEx(), fileConfig.getNameRegEx());
    }

    @Override
    public int hashCode() {
        int result = Objects.hashCode(getNameSplit());
        result = 31 * result + Objects.hashCode(getSimplePrefix());
        result = 31 * result + Objects.hashCode(getRollbackPrefix());
        result = 31 * result + Objects.hashCode(getAllwaysPrefix());
        result = 31 * result + Objects.hashCode(getNameRegEx());
        return result;
    }

    public String getNameSplit() {
        return nameSplit;
    }

    public void setNameSplit(String nameSplit) {
        this.nameSplit = nameSplit;
    }

    public String getSimplePrefix() {
        return simplePrefix;
    }

    public void setSimplePrefix(String simplePrefix) {
        this.simplePrefix = simplePrefix;
    }

    public String getRollbackPrefix() {
        return rollbackPrefix;
    }

    public void setRollbackPrefix(String rollbackPrefix) {
        this.rollbackPrefix = rollbackPrefix;
    }

    public String getAllwaysPrefix() {
        return allwaysPrefix;
    }

    public void setAllwaysPrefix(String allwaysPrefix) {
        this.allwaysPrefix = allwaysPrefix;
    }

    public String getNameRegEx() {
        return nameRegEx;
    }

    public void setNameRegEx(String nameRegEx) {
        this.nameRegEx = nameRegEx;
    }

    public FileConfig() {
    }

    public FileConfig(String nameSplit, String simplePrefix, String rollbackPrefix, String allwaysPrefix, String nameRegEx) {
        this.nameSplit = nameSplit;
        this.simplePrefix = simplePrefix;
        this.rollbackPrefix = rollbackPrefix;
        this.allwaysPrefix = allwaysPrefix;
        this.nameRegEx = nameRegEx;
    }
}
